#ifndef DNS_CACHE_H_
#define DNS_CACHE_H_

#include <netinet/in.h>
#include <time.h>

#define DF_FREE_KEY             1 /* auto free key's memory when clean */
#define DF_FREE_VALUE           2 /* auto free value's memory when change or clean */

typedef size_t hash_t;
typedef void free_cb(void *);

struct dict_entry {
    hash_t hash;
    const char *key;
    const void *value;
};

struct dict {
    size_t mask;
    size_t used;
    size_t fill;
    struct dict_entry *tab;
};


struct dict *dict_create();
void dict_destroy(struct dict *dict, free_cb *key_free_cb, free_cb *value_free_cb);
void dict_clean(struct dict *dict, free_cb *key_free_cb, free_cb *value_free_cb);

int dict_set(struct dict *dict, const char *key, const void *value,
        const char **oldkey, const void **oldvalue);
const void *dict_get(struct dict *dict, const char *key, const char **oldkey);
void dict_del(struct dict *dict, const char *key, const char **oldkey,
        const void **oldvalue);

#endif /* DNS_CACHE_H_ */
